package com.sskj.givecoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.givecoin.MyAppLication;
import com.sskj.givecoin.m.HttpConfig;
import com.sskj.givecoin.m.bean.HttpData;
import com.sskj.givecoin.m.http.JsonCallBack;
import com.sskj.givecoin.p.base.BasePresenter;
import com.sskj.givecoin.utils.ToastUtil;
import com.sskj.givecoin.v.activity.ApplyAgentPersonActivity;

public class ApplyAgentPersonPresenter extends BasePresenter<ApplyAgentPersonActivity> {
    public void sendCode() {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
                .params("mobile", MyAppLication.getMobile())
                .params("type", 3)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        ToastUtil.showShort(httpListData.getMsg());
                        mView.onSendSmsSuccess();
                    }
                });
    }

    public void sendEmail() {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL)
                .params("email", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        ToastUtil.showShort(httpListData.getMsg());
                        mView.onSendSmsSuccess();
                    }
                });
    }

    public void applyAgent(String code) {

        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.APPLY_AGENT)
                .params("code", code)
                .params("mobile", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData> response) {
                        if (response.body().getStatus() == 200) {
                            ToastUtil.showShort(response.body().getMsg());
                            mView.finish();
                        }
                    }
                });
    }
}
